1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module sourceview.LanguageManager;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import glib.c.functions;
30 private import gobject.ObjectG;
31 private import sourceview.Language;
32 private import sourceview.c.functions;
33 public  import sourceview.c.types;
34 
35 
36 /**
37  * Provides access to [class@Language]s.
38  * 
39  * `GtkSourceLanguageManager` is an object which processes language description
40  * files and creates and stores [class@Language] objects, and provides API to
41  * access them.
42  * 
43  * Use [func@LanguageManager.get_default] to retrieve the default
44  * instance of `GtkSourceLanguageManager`, and
45  * [method@LanguageManager.guess_language] to get a [class@Language] for
46  * given file name and content type.
47  */
48 public class LanguageManager : ObjectG
49 {
50 	/** the main Gtk struct */
51 	protected GtkSourceLanguageManager* gtkSourceLanguageManager;
52 
53 	/** Get the main Gtk struct */
54 	public GtkSourceLanguageManager* getLanguageManagerStruct(bool transferOwnership = false)
55 	{
56 		if (transferOwnership)
57 			ownedRef = false;
58 		return gtkSourceLanguageManager;
59 	}
60 
61 	/** the main Gtk struct as a void* */
62 	protected override void* getStruct()
63 	{
64 		return cast(void*)gtkSourceLanguageManager;
65 	}
66 
67 	/**
68 	 * Sets our main struct and passes it to the parent class.
69 	 */
70 	public this (GtkSourceLanguageManager* gtkSourceLanguageManager, bool ownedRef = false)
71 	{
72 		this.gtkSourceLanguageManager = gtkSourceLanguageManager;
73 		super(cast(GObject*)gtkSourceLanguageManager, ownedRef);
74 	}
75 
76 
77 	/** */
78 	public static GType getType()
79 	{
80 		return gtk_source_language_manager_get_type();
81 	}
82 
83 	/**
84 	 * Creates a new language manager.
85 	 *
86 	 * If you do not need more than one language manager or a private language manager
87 	 * instance then use [func@LanguageManager.get_default] instead.
88 	 *
89 	 * Returns: a new #GtkSourceLanguageManager.
90 	 *
91 	 * Throws: ConstructionException GTK+ fails to create the object.
92 	 */
93 	public this()
94 	{
95 		auto __p = gtk_source_language_manager_new();
96 
97 		if(__p is null)
98 		{
99 			throw new ConstructionException("null returned by new");
100 		}
101 
102 		this(cast(GtkSourceLanguageManager*) __p, true);
103 	}
104 
105 	/**
106 	 * Returns the default #GtkSourceLanguageManager instance.
107 	 *
108 	 * Returns: a #GtkSourceLanguageManager.
109 	 *     Return value is owned by GtkSourceView library and must not be unref'ed.
110 	 */
111 	public static LanguageManager getDefault()
112 	{
113 		auto __p = gtk_source_language_manager_get_default();
114 
115 		if(__p is null)
116 		{
117 			return null;
118 		}
119 
120 		return ObjectG.getDObject!(LanguageManager)(cast(GtkSourceLanguageManager*) __p);
121 	}
122 
123 	/**
124 	 * Appends @path to the list of directories where the @manager looks for
125 	 * language files.
126 	 *
127 	 * See [method@LanguageManager.set_search_path] for details.
128 	 *
129 	 * Params:
130 	 *     path = a directory or a filename.
131 	 *
132 	 * Since: 5.4
133 	 */
134 	public void appendSearchPath(string path)
135 	{
136 		gtk_source_language_manager_append_search_path(gtkSourceLanguageManager, Str.toStringz(path));
137 	}
138 
139 	/**
140 	 * Gets the [class@Language] identified by the given @id in the language
141 	 * manager.
142 	 *
143 	 * Params:
144 	 *     id = a language id.
145 	 *
146 	 * Returns: a #GtkSourceLanguage, or %NULL
147 	 *     if there is no language identified by the given @id. Return value is
148 	 *     owned by @lm and should not be freed.
149 	 */
150 	public Language getLanguage(string id)
151 	{
152 		auto __p = gtk_source_language_manager_get_language(gtkSourceLanguageManager, Str.toStringz(id));
153 
154 		if(__p is null)
155 		{
156 			return null;
157 		}
158 
159 		return ObjectG.getDObject!(Language)(cast(GtkSourceLanguage*) __p);
160 	}
161 
162 	/**
163 	 * Returns the ids of the available languages.
164 	 *
165 	 * Returns: a %NULL-terminated array of strings containing the ids of the available
166 	 *     languages or %NULL if no language is available.
167 	 *     The array is sorted alphabetically according to the language name.
168 	 *     The array is owned by @lm and must not be modified.
169 	 */
170 	public string[] getLanguageIds()
171 	{
172 		return Str.toStringArray(gtk_source_language_manager_get_language_ids(gtkSourceLanguageManager));
173 	}
174 
175 	/**
176 	 * Gets the list directories where @lm looks for language files.
177 	 *
178 	 * Returns: %NULL-terminated array
179 	 *     containing a list of language files directories.
180 	 *     The array is owned by @lm and must not be modified.
181 	 */
182 	public string[] getSearchPath()
183 	{
184 		return Str.toStringArray(gtk_source_language_manager_get_search_path(gtkSourceLanguageManager));
185 	}
186 
187 	/**
188 	 * Picks a [class@Language] for given file name and content type,
189 	 * according to the information in lang files.
190 	 *
191 	 * Either @filename or @content_type may be %NULL. This function can be used as follows:
192 	 *
193 	 * ```c
194 	 * GtkSourceLanguage *lang;
195 	 * GtkSourceLanguageManager *manager;
196 	 * lm = gtk_source_language_manager_get_default ();
197 	 * lang = gtk_source_language_manager_guess_language (manager, filename, NULL);
198 	 * gtk_source_buffer_set_language (buffer, lang);
199 	 * ```
200 	 *
201 	 * or
202 	 *
203 	 * ```c
204 	 * GtkSourceLanguage *lang = NULL;
205 	 * GtkSourceLanguageManager *manager;
206 	 * gboolean result_uncertain;
207 	 * gchar *content_type;
208 	 *
209 	 * content_type = g_content_type_guess (filename, NULL, 0, &result_uncertain);
210 	 * if (result_uncertain)
211 	 * {
212 	 * g_free (content_type);
213 	 * content_type = NULL;
214 	 * }
215 	 *
216 	 * manager = gtk_source_language_manager_get_default ();
217 	 * lang = gtk_source_language_manager_guess_language (manager, filename, content_type);
218 	 * gtk_source_buffer_set_language (buffer, lang);
219 	 *
220 	 * g_free (content_type);
221 	 * ```
222 	 *
223 	 * etc. Use [method@Language.get_mime_types] and [method@Language.get_globs]
224 	 * if you need full control over file -> language mapping.
225 	 *
226 	 * Params:
227 	 *     filename = a filename in Glib filename encoding, or %NULL.
228 	 *     contentType = a content type (as in GIO API), or %NULL.
229 	 *
230 	 * Returns: a #GtkSourceLanguage, or %NULL if there
231 	 *     is no suitable language for given @filename and/or @content_type. Return
232 	 *     value is owned by @lm and should not be freed.
233 	 */
234 	public Language guessLanguage(string filename, string contentType)
235 	{
236 		auto __p = gtk_source_language_manager_guess_language(gtkSourceLanguageManager, Str.toStringz(filename), Str.toStringz(contentType));
237 
238 		if(__p is null)
239 		{
240 			return null;
241 		}
242 
243 		return ObjectG.getDObject!(Language)(cast(GtkSourceLanguage*) __p);
244 	}
245 
246 	/**
247 	 * Prepends @path to the list of directories where the @manager looks
248 	 * for language files.
249 	 *
250 	 * See [method@LanguageManager.set_search_path] for details.
251 	 *
252 	 * Params:
253 	 *     path = a directory or a filename.
254 	 *
255 	 * Since: 5.4
256 	 */
257 	public void prependSearchPath(string path)
258 	{
259 		gtk_source_language_manager_prepend_search_path(gtkSourceLanguageManager, Str.toStringz(path));
260 	}
261 
262 	/**
263 	 * Sets the list of directories where the @lm looks for
264 	 * language files.
265 	 *
266 	 * If @dirs is %NULL, the search path is reset to default.
267 	 *
268 	 * At the moment this function can be called only before the
269 	 * language files are loaded for the first time. In practice
270 	 * to set a custom search path for a `GtkSourceLanguageManager`,
271 	 * you have to call this function right after creating it.
272 	 *
273 	 * Since GtkSourceView 5.4 this function will allow you to provide
274 	 * paths in the form of "resource:///" URIs to embedded `GResource`s.
275 	 * They must contain the path of a directory within the `GResource`.
276 	 *
277 	 * Params:
278 	 *     dirs = a %NULL-terminated array of
279 	 *         strings or %NULL.
280 	 */
281 	public void setSearchPath(string[] dirs)
282 	{
283 		gtk_source_language_manager_set_search_path(gtkSourceLanguageManager, Str.toStringzArray(dirs));
284 	}
285 }